<template>
  <div>
    <el-table
      :data="announceList"
      stripe
      style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="table-expand" label-width="80px">
            <el-form-item label="主题">
              <span>{{ props.row.title }}</span>
            </el-form-item><br>
            <el-form-item label="内容">
              <span v-html="props.row.content"></span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
        type="index"
        label="序号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="title"
        label="主题"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="时间">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">查看</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <div class="pagination" style="text-align: center">
      <el-pagination
        @current-change="handleCurrentChange"
        :page-size="pageSize"
        :hide-on-single-page="false"
        layout="prev, pager, next"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AnnounceList',
  data () {
    return {
      announceList: [],
      total: 0,
      pageSize: 10
    }
  },
  mounted () {
    this.getSize()
    this.getListAnnounce(1, this.pageSize)
  },
  methods: {
    // 统计数量
    getSize () {
      var _this = this
      this.$axios.post('/api/notify/getSizeAnnounce')
        .then(function (response) {
          var result = response.data
          if (result.isSuccess) {
            _this.total = parseInt(result.result)
          }
        })
    },
    // 获取公告
    getListAnnounce (page, pageSize) {
      var _this = this
      var announceQueryData = {
        page: page,
        pageSize: pageSize
      }
      this.$axios.post('/api/notify/getListAnnounce',
        this.$qs.stringify({
          announceQueryData: JSON.stringify(announceQueryData)
        }))
        .then(function (response) {
          var result = response.data
          if (result.isSuccess) {
            _this.announceList = result.result
          }
        })
    },
    // 下方分页点击
    handleCurrentChange (page) {
      this.getListAnnounce(page, this.pageSize)
    },
    handleEdit (index, row) {
    },
    handleDelete (index, row) {
    }
  }
}
</script>

<style scoped>

  .table-expand {
    font-size: 0;
  }
  .table-expand label {
    color: #99a9bf;
    font-weight: bolder;
  }
  .table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
    border-bottom: 1px solid #d2dce0;
  }
</style>
